# Copyright (C) 2006  Stephane Alnet
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 

#
# For more information visit http://carrierclass.net/
#

use strict;
use warnings;

package CCNCore::Model::Groups;
use Jifty::DBI::Schema;


use CCNCore::Record schema {

    column name =>
        type is 'text',
        is mandatory,
        filters are 'Jifty::DBI::Filter::utf8',
        since '0.0.1',
        label is 'Group Name',
        hints is 'The name for this group of persons or groups.';

    column parent =>
        references CCNCore::Model::Groups,
        is immutable,
        since '0.0.1',
        label is 'Parent group',
        hints is 'The parent group for this group.';

};

use CCNCore::Mixin::Active;

# Your model-specific methods go here.

sub since { 0.0.1 }
sub menu { 'User Management' }

# XXX Need code to verify that parent_id is NOT NULL except for the root group.

1;

__END__

=pod

 CREATE TABLE "ui_group" (
     -- #compute SELECT $_group AS parent_pk, CASE COUNT(*) WHEN 0 THEN 1 ELSE MAX(pk)+1 END AS pk FROM ui_group;
 
     "pk"                INTEGER NOT NULL PRIMARY KEY,               -- @pk      "hidden" nomodify aka ui_group_pk
 
     -- short name (FQDN component)
     "parent_pk"         INTEGER REFERENCES ui_group(pk),            -- @pk      "Parent group"  nomodify
 
     -- web-oriented properties
     -- displayed name for the group
     "label"             TEXT NOT NULL,                              -- @label   "Group Name"
 
     -- web theme
         -- apply the base theme from this group (NULL=apply parent's)
         -- default URL = /theme/<web_theme_group>/default.css
         -- when a theme is created, the elements are copied from the
         -- default (root) theme or parent theme (if any)
 
     -- billing-oriented properties
 
 
     --
     CHECK ( CASE pk WHEN 0 THEN parent_pk IS NULL ELSE parent_pk IS NOT NULL END )
 ) _{OPTIONS}_;
 
 -- The parent_pk of the root group is NULL. (This should be the only such group.)
 INSERT INTO ui_group(pk,label) VALUES (0,'The Root Group');

=cut
